package org.okcjug.december.google;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.Collections;

import org.junit.Assert;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;

public class MultiMapTestBed {
	
	private static final ImmutableList<BigDecimal> scores = ImmutableList.of(new BigDecimal("65345"),
			new BigDecimal("63358"), new BigDecimal("25713"), new BigDecimal("4259"));
	
	public void simpleMultiMap(){
		//OLD WAY
		Map<String, Set<BigDecimal>> oldWay = new HashMap<String, Set<BigDecimal>>();
		
		for(BigDecimal score : scores){
			Set<BigDecimal> values = oldWay.get("paul");
			if(values == null){
				values = new HashSet<BigDecimal>();
				values.add(score);
				oldWay.put("paul", values);
			}else{
				values.add(score);
			}
		}
		
		//new way
		Multimap<String, BigDecimal> tapDefenseScores = Multimaps.newHashMultimap();
		tapDefenseScores.put("paul", new BigDecimal("65325"));
		tapDefenseScores.put("paul", new BigDecimal("63358"));
		tapDefenseScores.put("paul", new BigDecimal("4259"));
		tapDefenseScores.put("mitch", new BigDecimal("6259"));
		
		//find max value
		BigDecimal topScore = Collections.max(tapDefenseScores.values());
		System.out.println("Top Score: " + topScore);
		Assert.assertEquals(topScore,  new BigDecimal("65325"));
	}
}

